
from django.db import models

# Create your models here.
from django.utils import timezone


class User(models.Model):
    username = models.CharField(verbose_name='用户名', max_length=32, null=True, blank=True)
    password = models.CharField(verbose_name='密码', max_length=64, null=True, blank=True)
    openid = models.CharField(verbose_name='openid', max_length=64)
    unionid = models.CharField(verbose_name='unionid', max_length=64)
    nickname = models.CharField(verbose_name='昵称', max_length=64)
    session_key = models.CharField(verbose_name='session_key', max_length=32)
    creat_time = models.IntegerField(verbose_name='注册时间', default=0, null=True, blank=True)
    update_time = models.IntegerField(verbose_name='更新时间', default=0, null=True, blank=True)



class User_info(models.Model):
    uid = models.CharField(max_length=32, primary_key=True)
    nickname = models.CharField(verbose_name='昵称', max_length=64)
    avatar_url = models.CharField(verbose_name='头像链接', max_length=512)
    gender_choices = (
        (0, '未知'),
        (1, '男'),
        (2, '女'),
    )
    gender = models.IntegerField(verbose_name='性别', choices=gender_choices)
    creat_time = models.IntegerField(verbose_name='注册时间', null=True, blank=True)
    update_time = models.IntegerField(verbose_name='更新时间', null=True, blank=True)

    def __str__(self):
        # admin后台返回
        return self.uid


class Sns_content(models.Model):
    user = models.ForeignKey(verbose_name='用户id', to='User_info', on_delete=models.DO_NOTHING)
    content = models.CharField(verbose_name='动态内容', max_length=512)
    type_choices = (
        (1, '纯文本'),
        (2, '图标'),
        (3, '视频'),
        (4, '音频'),
    )
    type = models.SmallIntegerField(verbose_name='状态', choices=type_choices)
    topic = models.ForeignKey(verbose_name='话题id', to='Topic', null=True, blank=True, on_delete=models.DO_NOTHING)
    imgs_path = models.CharField(verbose_name='图片路径', max_length=512, null=True, blank=True)
    video_path = models.CharField(verbose_name='视频路径', max_length=512, null=True, blank=True)
    audio_path = models.CharField(verbose_name='音频路径', max_length=512, null=True, blank=True)
    read_num = models.IntegerField(verbose_name='浏览数量', default=0)
    like_num = models.IntegerField(verbose_name='点赞数量', default=0)
    comment_num = models.IntegerField(verbose_name='评论数量', default=0)
    status_choices = (
        (1, '展示'),
        (0, '不展示'),
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_choices, default=1)
    creat_time = models.IntegerField(verbose_name='发布时间', null=True, blank=True)
    update_time = models.IntegerField(verbose_name='更新时间', null=True, blank=True)



class Sns_comment(models.Model):
    sns = models.ForeignKey(verbose_name='动态id', to='Sns_content', related_name='sns_content_comment',
                            on_delete=models.DO_NOTHING)
    content = models.TextField(verbose_name='评论内容')
    user = models.ForeignKey(verbose_name='评论者', to='User_info', on_delete=models.DO_NOTHING)

    # related_name主动设置一个反向关联的字段
    pid = models.ForeignKey(verbose_name='回复评论id', related_name='parent', to='self', null=True, blank=True,
                            on_delete=models.DO_NOTHING)
    root = models.ForeignKey(verbose_name='根评论', to='self', null=True, blank=True, related_name='roots', on_delete=models.DO_NOTHING)
    depth = models.PositiveIntegerField(verbose_name='评论层级', default=1)

    status_choices = (
        (1, '展示'),
        (0, '不展示'),
    )
    status = models.SmallIntegerField(verbose_name='展示状态', choices=status_choices, default=1)
    child_num = models.IntegerField(verbose_name='回复数量', default=0)
    like_num = models.IntegerField(verbose_name='点赞数量', default=0)
    creat_time = models.IntegerField(verbose_name='发布时间', null=True, blank=True)
    update_time = models.IntegerField(verbose_name='更新时间', null=True, blank=True)


class Topic(models.Model):
    title = models.CharField(verbose_name='话题文案', max_length=64)
    count = models.IntegerField(verbose_name='发布数量', default=0)

class Sns_image(models.Model):
    sns = models.ForeignKey(verbose_name='动态id', to='Sns_content', on_delete=models.DO_NOTHING)
    path = models.CharField(verbose_name='图片路径', max_length=512)
    key = models.CharField(verbose_name='对象名称', max_length=64)

class Illegal_words(models.Model):
    word = models.CharField(verbose_name='词语', max_length=32)
